package com.jcf.springboot.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@Slf4j
@ControllerAdvice
public class GlobalException extends RuntimeException {

    /**
     * 处理全局异常
     */
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R exception(Exception exception) {
        log.error("服务器内部出错", exception);
        return R.ok().code(HttpStatus.INTERNAL_SERVER_ERROR.value()).data(exception).message("服务器内部出错");
    }


}
